import { openDB, deleteDB, wrap, unwrap } from 'idb';

const DB = "AwesomeGeoJSON";
const STORE = "cache";
const VERSION = 1.0;

let db;

init();

async function init() {
  if (db == null) {
    db = await openDB(DB, VERSION, {
      upgrade(db) {
        db.createObjectStore(STORE);
      },
    });
  }
}

export async function getItem(key) {
  await init();
  return (await db.get(STORE, key));
}

export async function setItem(key, value) {
  await init();
  await db.put(STORE, value, key);
}